import java.io.*;
import java.util.*;

class Read {
    StringTokenizer st=new StringTokenizer("");
    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
    public String next() throws IOException {
        while (!st.hasMoreTokens()){
            st=new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }
    public String nextLine() throws IOException {
        return bf.readLine();
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public long nextLong() throws  IOException {
        return Long.parseLong(next());
    }
}
public class Main {
    public static Read in=new Read();
    public static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main1(String[] args) throws IOException {
        int t= in.nextInt();
        while (t-->0){
            int a= in.nextInt(),b= in.nextInt();
            int num=a*b,k=0;
            for (int i = 1; i < num; i++) {
                if(num%i==0) k++;
                if(k>2) {
                    System.out.println("NO");
                    break;
                }
            }
            if(k==2){
                System.out.println("YES");
            }
        }
    }

    public static void main2(String[] args) throws IOException {
        int n= in.nextInt(),k= in.nextInt();
        int[] nums=new int[n];
        for (int i = 0; i < n; i++) {
            nums[i]= in.nextInt();
        }
        Arrays.sort(nums);
        if(nums[n-1]-nums[0]<=k) System.out.println(n);
        else {
            int left=0,right=0;
            int maxLen=0;
            while (right<n){
                while (nums[right]-nums[left]>k){
                    left++;
                }
                maxLen=Math.max(right-left+1,maxLen);
                right++;
            }
            System.out.println(maxLen);
        }
    }

    public static void main3(String[] args) throws IOException {
        int n= in.nextInt(),m= in.nextInt();
        char[] s1=in.next().toCharArray();
        char[] s2=in.next().toCharArray();
        int[][] dp=new int[n+1][m+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if(s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
            }
        }
        System.out.println(dp[n][m]);
    }

    public static void main4(String[] args) throws IOException {
        int n= in.nextInt(),k= in.nextInt();
        int[] nums=new int[n];
        int min=Integer.MAX_VALUE,pos=0;
        for (int i = 0; i < n; i++) {
            nums[i]= in.nextInt();
            if(min>nums[i]){
                min=nums[i];
                pos=i;
            }
        }
        int count=1;
        int sum=min;
        nums[pos]*=2;
        while (sum<=k) {
            min=Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                if(min>nums[i]){
                    min=nums[i];
                    pos=i;
                }
            }
            sum+=min;
            nums[pos]*=2;
            if(sum<=k) count++;
        }
        System.out.println(count);
    }

    public static void main5(String[] args) throws IOException {
        int n= in.nextInt(),k= in.nextInt();
        int[] nums=new int[n];
        PriorityQueue<Integer> queue=new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            nums[i]= in.nextInt();
            queue.offer(nums[i]);
        }
        int sum=0,count=0;
        while (sum<=k) {
            sum+= queue.peek();
            int a= queue.peek()*2;
            queue.poll();
            queue.offer(a);
            if(sum<=k){
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main6(String[] args) throws IOException {
        int t= in.nextInt();
        while (t-->0){
            int n= in.nextInt(),a= in.nextInt(),b= in.nextInt();
            int min=0;
            if(n<=2) {
                min=Math.min(2*a,b);
                System.out.println(min);
            } else if (3*a<=2*b) {
                int k=n/2;
                min=a*k;
                if(n%2!=0) {
                    min=Math.min(min+a,min-a+b);
                }
                System.out.println(min);
            }
            else {
                int k=n/3;
                min=b*k;
                if(n%3==1){
                    min=Math.min(min+Math.min(a,b),min-b+2*a);
                } else if (n%3==2) {
                    min=Math.min(min+Math.min(a,b),min-b+3*a);
                }
                System.out.println(min);
            }
        }
    }
    public int longestCommonSubsequence(String text1, String text2) {
        char[] s1=text1.toCharArray(),s2=text2.toCharArray();
        int[][] dp=new int[s1.length+1][s2.length+1];
        for(int i=1;i<=s1.length;i++){
            for(int j=1;j<=s2.length;j++){
                if(s1[i-1]==s2[j-1]) dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
            }
        }
        return dp[s1.length][s2.length];
    }
    public static long ret=0;
    public static boolean flag=false;
    public static long sum=0;
    public static void main7(String[] args) {
        Scanner in=new Scanner(System.in);
        long num=in.nextLong();
        long tmp=num;
        while (tmp>0) {
            sum+=tmp%10;
            tmp/=10;
        }
        dfs(num,ret);
        if(flag) System.out.println("YES");
        else System.out.println("NO");
    }

    private static void dfs(long num, long ret) {
        if(ret*2>=sum){
            if(ret*2==sum) flag=true;
            return;
        }
        dfs(num/10,ret);
        dfs(num/10,ret+num%10);
    }

    public static void main8(String[] args) {
        Scanner in=new Scanner(System.in);
        long t= in.nextInt();
        long len=0,sum=0;
        long r=t;
        while (r>0){
            sum=sum*10+r%10;
            r/=10;
            len++;
        }
        long f=t%10,g=sum/(long) Math.pow(10,len-1);
        if(f!=g){
            t=t*(long) Math.pow(10,len)+sum;
        }else {
            long s=0,a=t/10;
            while (a>0) {
                s=s*10+a%10;
                a/=10;
            }
            t=t*(long) Math.pow(10,len-1)+s;
        }
        boolean flag=false;
        for (int i = 2; i < t; i++) {
            if (t%i==0) {
                flag=true;
                break;
            }
        }
        if(flag) System.out.println("noprime");
        else System.out.println("prime");
    }

    public static void main9(String[] args) {
        Scanner in=new Scanner(System.in);
        int n= in.nextInt();
        System.out.println(fb(n));
    }

    private static int fb(int n) {
        if(n==1||n==2) return n;
        return 2*fb(n-1);
    }

    public static void main10(String[] args) {
        Scanner in=new Scanner(System.in);
        char[] s=in.next().toCharArray();
        int left=0,right=0;
        Map<Character,Integer> hash=new HashMap<>();
        int max=0;
        while (right<s.length) {
            hash.put(s[right],hash.getOrDefault(s[right],0)+1);
            while (hash.size()>2) {
                hash.put(s[left],hash.get(s[left])-1);
                if(hash.get(s[left])==0) hash.remove(s[left]);
                left++;
            }
            max=Math.max(max,right-left+1);
            right++;
        }
        System.out.println(max);
    }
    ArrayList<String> rest;
    int len;
    public ArrayList<String> Permutation (String str) {
        rest=new ArrayList<>();
        len=str.length();
        if(str.equals("")||str==null){
            rest.add(str);
            return rest;
        }
        dfs(str.toCharArray(),0);
        Collections.sort(rest);
        return rest;
    }

    private void dfs(char[] s,int i) {
        if(i==len){
            if(!rest.contains(s.toString())){
                rest.add(s.toString());
            }
            return;
        }
        for (int j = i; j < len; j++) {
            swap(i,j,s);
            dfs(s,j+1);
            swap(i,j,s);
        }
    }
    private void swap(int a,int b,char[] arr){
        char c=arr[a];
        arr[a]=arr[b];
        arr[b]=c;
    }

    public static void main11(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] s = in.next().toCharArray();
        int n = s.length;
        int num = 0;
        for (int i = n - 2; i >= 0; i--) {
            if (s[i] != '-') {
                num = num * 10 + (s[i] - '0');
            }
        }
        int sum = 0, k = 1;
        while (num > 0) {
            int a = num % 10;
            num /= 10;
            sum += a * k;
            k++;
        }
        sum = sum%11;
        if (sum == (s[n - 1] - '0')||(sum==10&&s[n-1]=='X')) {
            System.out.println("Right");
        } else {
            if(sum==10) {
                s[n-1]='X';
            }
            else{
                s[n-1]=(char)(sum+'0');
            }
            System.out.println(new String(s));
        }
    }
    public static boolean[][] vis;
    public static int[] dx={0,0,-1,1};
    public static int[] dy={-1,1,0,0};
    public static int min,path,n,m,a;
    public static void main12(String[] args) {
        Scanner in=new Scanner(System.in);
        n= in.nextInt();m= in.nextInt();
        char[][] s=new char[n][m];
        vis=new boolean[n][m];
        min=Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            s[i]=in.next().toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if(s[i][j]=='k'){
                    dfs(s,i,j);
                }
            }
        }
        if(path==0) System.out.println(-1);
        else {
            System.out.println(path+" "+min);
        }
    }

    private static void dfs(char[][] s, int i, int j) {
        vis[i][j]=true;
        if(s[i][j]=='e') {
            min=Math.min(min,a);
            path++;
            return;
        }
        for (int k = 0; k < 4; k++) {
            int x=i+dx[k],y=j+dy[k];
            if(x>=0&&x<n&&y>=0&&y<m&&!vis[x][y]&&s[x][y]!='*'){
                a++;
                dfs(s,x,y);
                a--;
            }
        }
    }
    public int solve (int[][] matrix) {
        n=matrix.length;m=matrix[0].length;
        vis=new boolean[n][m];
        int ret=1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ret=Math.max(ret,dfs(matrix,i,j));
            }
        }
        return ret;
    }

    private int dfs(int[][] matrix, int i, int j) {
        int len=1;
        for (int k = 0; k < 4; k++) {
            int x=i+dx[k],y=j+dy[k];
            if(x>=0&&x<n&&y>=0&&y<m&&!vis[x][y]&&matrix[x][y]>matrix[i][j]){
                vis[x][y]=true;
                len=Math.max(len,1+dfs(matrix,x,y));
                vis[x][y]=false;
            }
        }
        return len;
    }

    public static void main13(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int max = 0, k = 0;
            while (max <= n) {
                max = (int) Math.pow(2, k) - 1;
                k++;
            }
            max = (max + 1) / 2 - 1;
            System.out.println(max);
        }
    }
    public static boolean[] check;
    public static void main14(String[] args) {
        Scanner in=new Scanner(System.in);
        n=in.nextInt();m=in.nextInt();
        int[] nums=new int[n];
        check=new boolean[n];
        for (int i = 0; i < n; i++) {
            nums[i]=i+1;
        }
        dfs(nums,0);
    }

    private static void dfs(int[] nums, int i) {
        if (sum == m) {
            for (int j = 0; j < nums.length; j++) {
                if (check[j]) System.out.print(j + 1 + " ");
            }
            System.out.println();
            return;
        }
        if (sum > m||i>=n) return;
        sum += nums[i];
        check[i] = true;
        dfs(nums, i + 1);
        sum -= nums[i];
        check[i] = false;
        dfs(nums,i+1);
    }

    public static void main15(String[] args) {
        Scanner in=new Scanner(System.in);
        String s1= " "+in.next(),s2= " "+in.next();
        int n=s1.length(),m=s2.length();
        int[][] dp=new int[n][m];
        for (int i = 0; i < n; i++) {
            dp[i][0]=i;
        }
        for (int i = 0; i < m; i++) {
            dp[0][i]=i;
        }
        for (int i = 1; i < n; i++) {
            for (int j = 1; j < m; j++) {
                if(s1.charAt(i)==s2.charAt(j)) {
                    dp[i][j]=dp[i-1][j-1];
                }
                else {
                    dp[i][j]=Math.min(dp[i][j-1]+1,Math.min(dp[i-1][j-1]+1,dp[i-1][j]+1));
                }
            }
        }
        System.out.println(dp[n-1][m-1]);
    }

    public static void main16(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        Map<Integer,Integer> hash=new HashMap<>();
        int ret=0;
        while (n>0) {
            int num=n%10;
            if(!hash.containsKey(num)) {
                ret=ret*10+num;
                hash.put(num,1);
            }
            n/=10;
        }
        System.out.println(ret);
    }

    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        char[] s=in.next().toCharArray();
        int[] g=new int[26],f=new int[26],dp=new int[s.length];
        int ret=0;
        for (int i = 0; i < s.length; i++) {
            dp[i]=f[s[i]-'a'];
            ret+=dp[i];
            g[s[i]-'a']=g[s[i]-'a']+1;
            f[s[i]-'a']=f[s[i]-'a']+i-g[s[i]-'a'];
        }
        System.out.println(ret);
    }
}